<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test js</title>
</head>
<body>
    <a href="http://www.baidu.com" id="B-baidu" class="link">www.baidu.com</a>
    <a href="http://www.2345.com" id="B-2345" style="color: red;font-size: 25px;font-weight: bold;" class="link">www.2345.com</a>
    <a href="http://www.taobao.com" id="B-taobao" class="links">www.taobao.com</a>
    <button type="button" id="B-try" onclick="tryIt()">Try it!</button>
<script type="text/javascript">
    var baidu = document.getElementById("B-baidu");
    console.log(baidu.getAttribute("href"), baidu.href);//得到href属性
    console.log(baidu.getAttribute("id"), baidu.id);//方法要打括号（），属性不用打括号
    console.log(baidu.getAttribute("class"), baidu.className);//class的特殊性  Attribute 属性

    baidu.setAttribute("href","http://baidu.com");//设置属性
    console.log(baidu.getAttribute("href"));

    baidu.href = "www.baidu.com";
    console.log(baidu.href);

    baidu.setAttribute("href", baidu.id);//将href改成id的值
    baidu.href = baidu.className;

    console.log(document.getElementById("B-2345"));
    console.log(document.getElementsByTagName("a"));//获取页面上所有的a标签 tag 标签名称
    console.log(document.getElementsByClassName("link"));//用相同名称获取相同元素，返回值为数组；
    var aLinks = document.getElementsByClassName("link");
    var a2345 = aLinks.item(1);
    a2345.setAttribute("id",a2345.href);
    console.log(a2345);
    console.log(aLinks.length, aLinks.item(1));
    a2345.setAttribute("href",baidu.className);
    console.log(baidu.innerText);//内部文本
    a2345.innerText = baidu.innerText;
    /*修改style*/
    console.log(a2345.style.color, a2345.style.fontSize);

    a2345.style.color = "green";
    a2345.style.fontSize = "21px";

    var as = document.getElementsByTagName("a");
    var taobao = as[2];
    //taobao.setAttribute("style",a2345.style.cssText);
    //taobao.style.fontWeight = "";
    console.log(taobao);
    taobao.style.color = a2345.style.color;
    taobao.style.fontWeight = a2345.style.fontWeight;
    baidu.style.display = "none";
    //baidu.style.fontSize = "26px";
    baidu.style.display = "inline";
    if(baidu.style.display == "none"){
        baidu.style.fontSize = "26px";
    }

    var className = "links"; // links link
    className = className + " link";
    console.log(className);

    taobao.className = taobao.className + " link";

    var a = 1;
    //a += 1;//等同于a=a+1
    //a++; //1
    console.log(++a); // 2
    console.log(a); // 2

    function tryIt(){
       // alert("hello world!!!!!");
        var baidu = document.getElementById("B-baidu");
        if(baidu.style.display == "inline"){
            baidu.style.display = "none";
        }
        else{
            baidu.style.display = "inline";

        }
    }//function 定义一个函数；


</script>
</body>
</html>